<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use App\Models\ConfigWithdraw;
use Encore\Admin\Controllers\AdminController;

class ConfigWithdrawsController extends AdminController
{
    protected $title = '提现配置';
    
    protected function form()
    {
        $form = new Form(new ConfigWithdraw());

        $form->radio('is_open', '开放提现')->options(config('site.bool'))->default(true);
        $form->select('allowed_channel', '提现渠道')->options(config('site.withdraw.channels'))->default('local');
        //$form->checkbox('allowed_methods', '提现方式')->options(config('site.withdraw.methods'))->default(['wx_wallet']);
        //$form->checkbox('allowed_weekdays', '提现开放日')->options(config('site.withdraw.weekdays'))->default(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']);
        $form->currency('allowed_lowest_amount', '最低起提')->symbol('￥')->default(0)->help('NOTE: 单笔提现起提额度，0为不限');
        $form->currency('allowed_highest_amount', '最高限额')->symbol('￥')->default(0)->help('NOTE: 单笔提现最高额度，0为不限'); 
        $form->currency('sandpay_quota', '银行卡最低起提')->symbol('￥')->default(0)->help('NOTE: 银行卡单笔提现起提额度，0为不限');
        //$form->number('multiple', '倍数基数')->default(0)->help('NOTE: 提现额度倍增基数，0为不限');
        //$form->radio('charge_type', '服务费扣除方式')->options(config('site.withdraw.charge_types'))->default('in')->help('NOTE: 所提现额度内扣除，或 提现额度外账户余额中扣除');
        $form->rate('charge_percent', '阿里服务费收取比例')->default(1)->help('NOTE: 收取提现金额的服务费比例，0为不限');
        $form->rate('xzb_charge_percent', '银行卡服务费收取比例')->default(1)->help('NOTE: 银行卡收取提现金额的服务费比例，0为不限');
        //$form->currency('allowed_lowest_charge', '最低服务费')->symbol('￥')->default(0)->help('NOTE: 低于此额度，以此额度收取，0为不限');
        $form->currency('allowed_highest_charge', '最高服务费')->symbol('￥')->default(0)->help('NOTE: 高于此额度，以此额度收取，0为不限');
        $form->number('frequency', '每日提现频率')->default(1)->min(0)->help('NOTE: 每人每日累计可提现次数, 0为不限');
        $form->timeRange('withdraw_start_time', 'withdraw_end_time', '提现时间范围');

        $form->radio('is_alipay_withdraw_open', '支付宝提现开关')->options(config('site.bool'))->default(false);

         $form->radio('is_bank_withdraw_open', '银行卡提现开关')->options(config('site.bool'))->default(false);

        $form->textarea('description', '提现说明');
        
        $this->formTools($form);
        $this->formSaved($form);
        $this->formFooter($form);

        return $form;
    }
	
	protected function formTools(Form $form)
	{
		$form->tools(function (Form\Tools $tools) {
			$tools->disableList();
			$tools->disableView();
			$tools->disableDelete();
		});
	}
	
	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('提现配置已更新', 'success');
			return redirect(route('admin.config-withdraws.edit', 1));
		});
	}
	
	protected function formFooter(Form $form)
	{
		$form->footer(function (Form\Footer $footer) {
			$footer->disableViewCheck();
			$footer->disableCreatingCheck();
			$footer->disableEditingCheck();
		});
	}
}
